<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BaseUsers {

	protected $m_intId;
	protected $m_strName;
	protected $m_strEmail;
	protected $m_strLogin;
	protected $m_strPassword;
	protected $m_intDepartment;
	protected $m_intReportingMgr;
	protected $m_strDtOfjoin;
	protected $m_strDtOfleave;
	protected $m_intTenure;
	protected $m_intBillingStatus;
	protected $m_intEmpStatus;
	protected $m_timeEmpShiftStart;
	protected $m_timeEmpShiftEnd;
	protected $m_intLockout;
	protected $m_strLockouttime;
	protected $m_strUnlocktime;
	protected $m_intAdmin;
	protected $m_intBanned;
	protected $m_intGrp;
	protected $m_intNAccessLevel;
	protected $m_charCabStatus;
	protected $m_strAddress;
	protected $m_strShiftIn;
	protected $m_intMailStatus;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_intId;
	}

	public function getName(){
		return $this->m_strName;
	}

	public function getEmail(){
		return $this->m_strEmail;
	}

	public function getLogin(){
		return $this->m_strLogin;
	}

	public function getPassword(){
		return $this->m_strPassword;
	}

	public function getDepartment(){
		return $this->m_intDepartment;
	}

	public function getReportingMgr(){
		return $this->m_intReportingMgr;
	}

	public function getDtOfjoin(){
		return $this->m_strDtOfjoin;
	}

	public function getDtOfleave(){
		return $this->m_strDtOfleave;
	}

	public function getTenure(){
		return $this->m_intTenure;
	}

	public function getBillingStatus(){
		return $this->m_intBillingStatus;
	}

	public function getEmpStatus(){
		return $this->m_intEmpStatus;
	}

	public function getEmpShiftStart(){
		return $this->m_timeEmpShiftStart;
	}

	public function getEmpShiftEnd(){
		return $this->m_timeEmpShiftEnd;
	}

	public function getLockout(){
		return $this->m_intLockout;
	}

	public function getLockouttime(){
		return $this->m_strLockouttime;
	}

	public function getUnlocktime(){
		return $this->m_strUnlocktime;
	}

	public function getAdmin(){
		return $this->m_intAdmin;
	}

	public function getBanned(){
		return $this->m_intBanned;
	}

	public function getGrp(){
		return $this->m_intGrp;
	}

	public function getNAccessLevel(){
		return $this->m_intNAccessLevel;
	}

	public function getCabStatus(){
		return $this->m_charCabStatus;
	}

	public function getAddress(){
		return $this->m_strAddress;
	}

	public function getShiftIn(){
		return $this->m_strShiftIn;
	}

	public function getMailStatus(){
		return $this->m_intMailStatus;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_intId = $Id;
	}

	public function setName( $Name ){
		$this->m_strName = $Name;
	}

	public function setEmail( $Email ){
		$this->m_strEmail = $Email;
	}

	public function setLogin( $Login ){
		$this->m_strLogin = $Login;
	}

	public function setPassword( $Password ){
		$this->m_strPassword = $Password;
	}

	public function setDepartment( $Department ){
		$this->m_intDepartment = $Department;
	}

	public function setReportingMgr( $ReportingMgr ){
		$this->m_intReportingMgr = $ReportingMgr;
	}

	public function setDtOfjoin( $DtOfjoin ){
		$this->m_strDtOfjoin = $DtOfjoin;
	}

	public function setDtOfleave( $DtOfleave ){
		$this->m_strDtOfleave = $DtOfleave;
	}

	public function setTenure( $Tenure ){
		$this->m_intTenure = $Tenure;
	}

	public function setBillingStatus( $BillingStatus ){
		$this->m_intBillingStatus = $BillingStatus;
	}

	public function setEmpStatus( $EmpStatus ){
		$this->m_intEmpStatus = $EmpStatus;
	}

	public function setEmpShiftStart( $EmpShiftStart ){
		$this->m_timeEmpShiftStart = $EmpShiftStart;
	}

	public function setEmpShiftEnd( $EmpShiftEnd ){
		$this->m_timeEmpShiftEnd = $EmpShiftEnd;
	}

	public function setLockout( $Lockout ){
		$this->m_intLockout = $Lockout;
	}

	public function setLockouttime( $Lockouttime ){
		$this->m_strLockouttime = $Lockouttime;
	}

	public function setUnlocktime( $Unlocktime ){
		$this->m_strUnlocktime = $Unlocktime;
	}

	public function setAdmin( $Admin ){
		$this->m_intAdmin = $Admin;
	}

	public function setBanned( $Banned ){
		$this->m_intBanned = $Banned;
	}

	public function setGrp( $Grp ){
		$this->m_intGrp = $Grp;
	}

	public function setNAccessLevel( $NAccessLevel ){
		$this->m_intNAccessLevel = $NAccessLevel;
	}

	public function setCabStatus( $CabStatus ){
		$this->m_charCabStatus = $CabStatus;
	}

	public function setAddress( $Address ){
		$this->m_strAddress = $Address;
	}

	public function setShiftIn( $ShiftIn ){
		$this->m_strShiftIn = $ShiftIn;
	}

	public function setMailStatus( $MailStatus ){
		$this->m_intMailStatus = $MailStatus;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into USERS (Name, Email, Login, Password, department, reporting_mgr, dt_ofjoin, dt_ofleave, tenure, billing_status, emp_status, emp_shift_start, emp_shift_end, lockout, lockouttime, unlocktime, admin, banned, grp, nAccessLevel, cab_status, address, shift_in, mail_status) values ('" . $this->getName() . "', '" . $this->getEmail() . "', '" . $this->getLogin() . "', '" . $this->getPassword() . "', " . $this->getDepartment() . ", " . $this->getReportingMgr() . ", '" . $this->getDtOfjoin() . "', '" . $this->getDtOfleave() . "', " . $this->getTenure() . ", " . $this->getBillingStatus() . ", " . $this->getEmpStatus() . ", " . $this->getEmpShiftStart() . ", " . $this->getEmpShiftEnd() . ", " . $this->getLockout() . ", '" . $this->getLockouttime() . "', '" . $this->getUnlocktime() . "', " . $this->getAdmin() . ", " . $this->getBanned() . ", " . $this->getGrp() . ", " . $this->getNAccessLevel() . ", " . $this->getCabStatus() . ", '" . $this->getAddress() . "', '" . $this->getShiftIn() . "', " . $this->getMailStatus() . ")");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE USERS set  Name= '" . $this->getName() . "', Email= '" . $this->getEmail() . "', Login= '" . $this->getLogin() . "', Password= '" . $this->getPassword() . "', department= " . $this->getDepartment() . ", reporting_mgr= " . $this->getReportingMgr() . ", dt_ofjoin= '" . $this->getDtOfjoin() . "', dt_ofleave= '" . $this->getDtOfleave() . "', tenure= " . $this->getTenure() . ", billing_status= " . $this->getBillingStatus() . ", emp_status= " . $this->getEmpStatus() . ", emp_shift_start= " . $this->getEmpShiftStart() . ", emp_shift_end= " . $this->getEmpShiftEnd() . ", lockout= " . $this->getLockout() . ", lockouttime= '" . $this->getLockouttime() . "', unlocktime= '" . $this->getUnlocktime() . "', admin= " . $this->getAdmin() . ", banned= " . $this->getBanned() . ", grp= " . $this->getGrp() . ", nAccessLevel= " . $this->getNAccessLevel() . ", cab_status= " . $this->getCabStatus() . ", address= '" . $this->getAddress() . "', shift_in= '" . $this->getShiftIn() . "', mail_status= " . $this->getMailStatus() . " where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM users WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'users'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}